﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace qly
{
    class HoadonDAL
    {
         public HoadonDAL()
        {

        }
        public DataTable  DocDanhSachHoaDon()
        {
            SqlConnection conn = SQLDatabase.Connection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from hoadon a, hanghoa b where a.mahang=b.mahang", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            return dt;
        }

        public void XoaHoaDon(string sohd)
        {
            SqlConnection conn = SQLDatabase.Connection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("delete from hoadon where sohd='"+sohd+"'", conn);
            cmd.ExecuteNonQuery();
        }
        public void ThemHoaDon(string hoadon, string mahang, string diengiai,double soluong, double dongia, double trigia, double khuyenmai)
        {
            SqlConnection conn = SQLDatabase.Connection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("insert into hoadon values('" + hoadon + "','" + mahang + "','" + soluong + "','" + dongia + "','" + trigia + "','" + khuyenmai + "',N'" + diengiai + "')", conn);
            cmd.ExecuteNonQuery();
        }
        public void SuaHoaDon(string hoadon, string mahang, string diengiai,double soluong, double dongia, double trigia, double khuyenmai)
        {
            SqlConnection conn = SQLDatabase.Connection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("update hoadon set mahang='"+mahang+"',soluong="+soluong+",dongia="+dongia+",trigia="+trigia+",khuyenmai="+khuyenmai+",diengiai=N'"+diengiai+"'where sohd='"+hoadon+"'", conn);
            cmd.ExecuteNonQuery();
        }
    }
}
